#! /bin/sh

if [ "" = "$1" ]; then
	PWD=`pwd`
	GOSRC=`dirname $PWD`
else
	GOSRC=$1/src
fi
export GOPATH=`dirname $GOSRC`
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
export XP_CONF=$GOPATH/src/xp/conf.cfg

alias gb='$GOPATH/src/xp/script/b.sh'
alias gd='$GOPATH/src/xp/script/d.sh'
alias ged='$GOPATH/src/xp/script/ed.sh'
alias xn='$GOPATH/src/xp/script/xn.sh'

# Linux
if [ -f ~/.bashrc ]; then
	ef=$HOME/.bashrc
# Darwin
elif [ -f ~/.bash_profile ]; then
	ef=$HOME/.bash_profile
fi

if [ ! -x $GOBIN/xp_tools_gen ]; then
	which make &>/dev/null
	if [ 0 -eq $? ]; then
		cd $GOPATH/src/xp/tools/gen && make &>/dev/null
	else
		cd $GOPATH/src/xp/tools/gen && gb && mv xp_tools_gen $GOPATH/bin/
	fi
	cd $GOPATH/src/xp
fi

if [ -f ~/.bashrc ]; then
	ef=$HOME/.bashrc
elif [ -f ~/.bash_profile ]; then
	ef=$HOME/.bash_profile
fi

#if [ $ef != "" ]; then
#	grep "xp env" $ef &>/dev/null || echo -e "\n# xp env\n. $GOPATH/src/xp/env.sh $GOPATH" >> $ef
#fi
